<template>
  <div>
    <h3>进修培训</h3>
    <div class="table-body">
      <vxe-toolbar style="height: 100px;">
        <template #buttons>
          <el-row style="margin-bottom: 20px;">
            <el-col :span="6">
              <el-select v-model="searchForm.empTypeId" size="small" multiple collapse-tags
                filterable clearable placeholder="选择工作类型">
                <el-option :label="item" :value="key" v-for="(item,key,index) in dict_empType" :key="index"></el-option>
              </el-select>
              <el-button type="success" size="small" @click="searchForm.empTypeId = Object.keys(dict_empType)">全选
              </el-button>
            </el-col>
            <el-col :span="10">
              <sportChangesportItem ref="sport2sportItem" search="search"
                :sportChangesportItemData="sportChangesportItemData" @selectDataChange='searchSelectDataChange' />
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6" style="display: flex;">
              <el-button type="success" icon="el-icon-plus" size="medium" @click="insertEvent">新增</el-button>
              <el-button type="success" icon="el-icon-printer" size="medium" @click="exportData">导出</el-button>
              <el-button type="success" icon="el-icon-printer" size="medium" @click="printEvent">打印</el-button>
            </el-col>
            <el-col :span="8">
              <el-date-picker size="small" v-model="doubleDate" type="daterange" align="right" unlink-panels
                range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
              </el-date-picker>
            </el-col>
            <el-col :span="5">
              <el-button type="success" size="small" icon="el-icon-s-promotion" @click="searchSubmit"
                style="margin: 0 10px;">
                搜索</el-button>
              <vxe-button @click="clearTableFilter" status="warning" icon="el-icon-refresh-right"> 清空</vxe-button>
            </el-col>
            <el-col :span="4">
              <vxe-input style="float: right;" v-model.trim.lazy="filterName" type="search" placeholder="快捷检索"
                @input="searchEvent"></vxe-input>
            </el-col>
          </el-row>
        </template>
      </vxe-toolbar>
      <vxe-table resizable ref="XTable" show-overflow border max-height="800" stripe highlight-hover-row highlight-current-row
        :loading="loading" :data="dataList" @sort-change="sortChange">
        <vxe-table-column field="emp" title="职员" sortable></vxe-table-column>
        <vxe-table-column field="empId2Type" title=" 专职" sortable></vxe-table-column>
        <vxe-table-column field="jempId2Type" title=" 兼职" sortable></vxe-table-column>
        <vxe-table-column field="beginDate" title="开始时间" sortable></vxe-table-column>
        <vxe-table-column field="endDate" title="结束时间" sortable></vxe-table-column>
        <vxe-table-column field="contentType" title="培训类型" sortable></vxe-table-column>
        <vxe-table-column field="content" title="主要内容" sortable></vxe-table-column>
        <vxe-table-column field="hostType" title="主办部门" sortable></vxe-table-column>
        <vxe-table-column field="orgName" title="主办单位" sortable></vxe-table-column>
        <vxe-table-column field="trainingLevel" title="培训等级" sortable></vxe-table-column>
        <vxe-table-column field="period" title="培训课时" sortable></vxe-table-column>
        <vxe-table-column field="address" title="授课地址" sortable></vxe-table-column>
        <vxe-table-column field="instructor" title="授课人" sortable></vxe-table-column>
        <vxe-table-column field="result" title="考试成绩" sortable></vxe-table-column>
        <vxe-table-column field="" title="操作" width="110">
          <template #default="{ row,rowIndex }">
            <el-button @click="editEvent(row,rowIndex)" type="success" size="medium" icon="el-icon-edit" circle></el-button>
            <el-button @click="deleteEvent(row)" type="danger" size="medium" icon="el-icon-delete" circle></el-button>
          </template>
        </vxe-table-column>
        <vxe-table-column field="createUser" title="录入人" sortable></vxe-table-column>
        <vxe-table-column field="checkUser" title="审核人" sortable>
          <template #default="{ row }">
            <span v-if="row.checkUserId!=0">{{row.checkUser}}</span>
            <el-link v-else @click="checkedEvent(row)" type="success">{{row.checkUser}}</el-link>
          </template>
        </vxe-table-column>
      </vxe-table>
      <vxe-pager :loading="loading" :current-page="page.currentPage" :page-size="page.pageSize" :total="page.totalResult"
        :layouts="['PrevPage', 'JumpNumber', 'NextPage', 'FullJump', 'Sizes', 'Total']" @page-change="handlePageChange">
      </vxe-pager>
    </div>
    <vxe-modal v-model="insertModal" title="进修培训">
      <template #default>
        <el-form inline-message ref="insertForm" :rules="rules" :model="insertForm" label-width="110px">
          <el-form-item label="运动项目" prop="sportId">
            <el-select v-model="insertForm.sportId" filterable clearable style="width: 100%;" placeholder="请选择" @change="sportChange">
              <el-option :label="item" :value="key" v-for="(item,key,index) in dict_sport" :key="index">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="运动小项" prop="sportItemId">
            <el-select v-model="insertForm.sportItemId" filterable clearable style="width: 100%;" placeholder="请选择" @change="sportItemChange">
              <el-option :label="item" :value="key" v-for="(item,key,index) in dict_sportItem" :key="index">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="教职员" prop="empId">
            <el-select v-model="insertForm.empId" filterable clearable style="width: 100%;" placeholder="请选择">
              <el-option :label="item" :value="key" v-for="(item,key,index) in empData" :key="index">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="开始时间" prop="beginDate">
            <el-date-picker type="date" placeholder="选择日期" v-model="insertForm.beginDate" style="width: 100%;">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="结束时间" prop="endDate">
            <el-date-picker type="date" placeholder="选择日期" v-model="insertForm.endDate" style="width: 100%;">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="培训类型" prop="contentTypeId">
            <el-select v-model="insertForm.contentTypeId" filterable clearable style="width: 100%;" placeholder="请选择">
              <el-option :label="item" :value="key" v-for="(item,key,index) in dict_contentType" :key="index">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="主要内容" prop="content">
            <el-input v-model="insertForm.content"></el-input>
          </el-form-item>
          <el-form-item label="主办部门" prop="hostTypeId">
            <el-select v-model="insertForm.hostTypeId" filterable clearable style="width: 100%;" placeholder="请选择">
              <el-option :label="item" :value="key" v-for="(item,key,index) in dict_hostType" :key="index"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="主办单位" prop="orgName">
            <el-input v-model="insertForm.orgName"></el-input>
          </el-form-item>
          <el-form-item label="培训等级" prop="trainingLevelId">
            <el-select v-model="insertForm.trainingLevelId" filterable clearable style="width: 100%;" placeholder="请选择">
              <el-option :label="item" :value="key" v-for="(item,key,index) in dict_trainingLevel" :key="index">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="培训课时" prop="perio">
            <el-input v-model="insertForm.perio"></el-input>
          </el-form-item>
          <el-form-item label="授课地址" prop="address">
            <el-input v-model="insertForm.address"></el-input>
          </el-form-item>
          <el-form-item label="授课人" prop="instructor">
            <el-input v-model="insertForm.instructor"></el-input>
          </el-form-item>
          <el-form-item label="考试成绩" prop="result">
            <el-input v-model="insertForm.result"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="warning" size="small" @click="insertModal = false">取消</el-button>
            <el-button type="success" size="small" icon="el-icon-s-promotion" @click="insertSave">保存</el-button>
          </el-form-item>
        </el-form>
      </template>
    </vxe-modal>
  </div>
</template>
<script>
  import {
    furtherEducation_selectByOrg,
    furtherEducation_insert,
    furtherEducation_update,
    furtherEducation_delete,
    furtherEducation_check,
    furtherEducation_select,
    currentRoleEmployee,
    sport_item_by_sportId
  } from '@/api/person.js'
  import {
    pId2sportIds4emp1,
    genEmpType,
    userId2EmpName,
    sport_by_org,
    sport_item_cache
  } from '@/api/dict.js'
  import sportChangesportItem from '@/components/sport2sportItem/sport2sportItem.vue'
  export default {
    components: {
      sportChangesportItem
    },
    data() {
      return {
        doubleDate: '',
        pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
        },
        defaultDataList: [],
        dataList: [],
        page: {
          currentPage: 1,
          pageSize: 10,
          totalResult: 0
        },
        loading: false,
        filterName: '',
        insertModal: false,
        dict_empId2Type: {},
        dict_jempId2Type: {},
        dict_pId2TypeId: {},
        dict_jpId2TypeId: {},
        dict_empType: {},
        dict_userId2empName: {},
        dict_emp: {},
        dict_sport: {},
        dict_sportItem: {},
        dict_createUser: {},
        dict_checkUser: {},
        dict_contentType: {
          1: "(继续教育)岗位培训",
          2: "(继续教育)短期培训",
          3: "(继续教育)各类讲座",
        },
        dict_hostType: {
          1: "体育部门",
          2: "教育主管部门",
        },
        dict_trainingLevel: {
          1: "国家级",
          2: "省级",
          3: "市级",
        },
        insertForm: {
          empId: '',
          sportId: '',
          sportItemId: '',
          beginDate: '',
          endDate: '',
          contentTypeId: '',
          content: '',
          hostTypeId: '',
          orgName: '',
          trainingLevelId: '',
          perio: '',
          address: '',
          instructor: '',
          result: '',
        },
        searchForm: {
          empTypeId: '',
          empId: '',
          sportId: '',
          sportItemId: '',
          beginDate: '',
          endDate: '',
        },
        sportItemData: [],
        rules: {
          beginDate: [{
            required: true,
            message: '这是必填项',
            trigger: 'blur'
          }, ],
        },
        isInsert: true,
        flowId: '',
        pid: '',
        empData: {},
        sportChangesportItemData: {},
        dict_sport: {},
        dict_sportItem: {},
        search: false,
        currentIndex: null,
      }
    },
    created() {
      this.init_dict().then(()=>{
        this.furtherEducation_selectByOrg()
      })
    },
    computed: {
      openDateValid() {
        if (this.insertForm.openDate && this.insertForm.closeDate) {
          if (this.insertForm.openDate > this.insertForm.closeDate) {
            this.$message.error('开始时间必须小于结束时间！')
            return false
          } else {
            return true
          }
        } else {
          return true
        }
      }
    },
    watch: {
      filterName(val) {
    	if(!val){
    	  this.page = {
    	  currentPage: 1,
    	  pageSize: 10,
    	  totalResult: 0,
    	  }
    	  this.search = false
    	  this.findList()
    	}
      }
    },
    methods: {
      searchSelectDataChange({
        sportId,
        sportItemId,
        person
      }) {
        this.searchForm.sportId = sportId
        this.searchForm.sportItemId = sportItemId
        this.searchForm.empId = person
      },
      insertSelectDataChange({
        sportId,
        sportItemId,
        person
      }) {
        this.insertForm.sportId = sportId
        this.insertForm.sportItemId = sportItemId
        this.insertForm.empId = person
      },
      clearTableFilter() {
        this.searchForm = {
          empTypeId: '',
          empId: '',
          sportId: '',
          sportItemId: '',
          beginDate: '',
          endDate: '',
        }
        this.sportChangesportItemData = {}
        this.furtherEducation_selectByOrg()
      },
      searchSubmit() {
        let data = {}
        if (this.searchForm.empTypeId) data.empTypeIdStr = this.searchForm.empTypeId.join(',')
        if (this.searchForm.empId) data.empId = this.searchForm.empId
        if (this.searchForm.sportId) data.sportId = this.searchForm.sportId
        if (this.searchForm.sportItemId) data.sportItemId = this.searchForm.sportItemId
        if (this.doubleDate){
          data.beginDateT = this.$moment(this.doubleDate[0]).format('YYYY-MM-DD') + ' 00:00:00'
          data.endDateT = this.$moment(this.doubleDate[1]).format('YYYY-MM-DD') + ' 00:00:00'
        }
        furtherEducation_select(data).then(res => {
          if (res.code === 200 && res.data.length != 0) {
            this.page = {
              currentPage: 1,
              pageSize: 10,
              totalResult: 0
            }
            this.init_data(res.data)
          } else {
            this.defaultDataList = []
          }
        }).then(() => {
          this.findList()
        })
      },
      deleteEvent(row) {
        this.$confirm('此操作将永久删除该条记录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          furtherEducation_delete({
            flowId: row.flowId,
            empId: row.empId
          }).then(res => {
            if (res.code === 200) {
              this.defaultDataList.forEach((item,index)=>{
              	if(item.flowId == row.flowId){
              	  this.defaultDataList.splice(index,1)
              	}
              })
              this.init_data(this.defaultDataList)
              this.findList()
              this.$message.success('删除成功！')
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
      checkedEvent(row) {
        this.$confirm('注意：审核过之后，该条数据将不能再被修改', '审核', {
          confirmButtonText: '√通过审核',
          cancelButtonText: '放弃审核',
          type: 'warning'
        }).then(() => {
          furtherEducation_check({
            flowId: row.flowId
          }).then(res => {
            if (res.code === 200) {
              this.furtherEducation_selectByOrg()
              this.$message.success('已审核.！')
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消审核.'
          });
        });
      },
      editEvent(row,rowIndex) {
        this.currentIndex = rowIndex
        if (row.checkUserId!=0) {
          this.$message.warning('已经审核过的数据不能修改')
        } else {
          this.flowId = row.flowId
          this.insertForm.sportId = row.sportId==0?'':row.sportId+''
          this.insertForm.sportItemId = row.sportItemId==0?'':row.sportItemId+''
          this.insertForm.empId = row.empId+''
          this.insertForm.beginDate = row.beginDate
          this.insertForm.endDate = row.endDate
          this.insertForm.contentTypeId = row.contentTypeId==0?'':row.contentTypeId+''
          this.insertForm.content = row.content
          this.insertForm.hostTypeId = row.hostTypeId==0?'':row.hostTypeId+''
          this.insertForm.orgName = row.orgName
          this.insertForm.trainingLevelId = row.trainingLevelId==0?'':row.trainingLevelId+''
          this.insertForm.perio = row.perio
          this.insertForm.address = row.address
          this.insertForm.instructor = row.instructor
          this.insertForm.result = row.result
          this.isInsert = false
          this.insertModal = true
        }
      },
      insertSave() {
        this.$refs.insertForm.validate((valid) => {
          if (valid && this.openDateValid ) {
            let data = {}
            if (this.insertForm.empId) data.empId = this.insertForm.empId
            if (this.insertForm.sportId) data.sportId = this.insertForm.sportId
            if (this.insertForm.sportItemId) {
              data.sportItemId = this.insertForm.sportItemId
            }else{
              data.sportItemId = 0
            }
            if (this.insertForm.empId2TypeId) data.empId2TypeId = this.insertForm.empId2TypeId
            if (this.insertForm.jempId2TypeId) data.jempId2TypeId = this.insertForm.jempId2TypeId
            if (this.insertForm.beginDate) data.beginDate = this.$moment(this.insertForm.beginDate).format(
              'YYYY-MM-DD') + ' 00:00:00'
            if (this.insertForm.endDate) data.endDate = this.$moment(this.insertForm.endDate).format('YYYY-MM-DD') +
              ' 00:00:00'
            if (this.insertForm.contentTypeId) data.contentTypeId = this.insertForm.contentTypeId
            if (this.insertForm.content) data.content = this.insertForm.content
            if (this.insertForm.hostTypeId) data.hostTypeId = this.insertForm.hostTypeId
            if (this.insertForm.orgName) data.orgName = this.insertForm.orgName
            if (this.insertForm.trainingLevelId) data.trainingLevelId = this.insertForm.trainingLevelId
            if (this.insertForm.perio) data.perio = this.insertForm.perio
            if (this.insertForm.address) data.address = this.insertForm.address
            if (this.insertForm.instructor) data.instructor = this.insertForm.instructor
            if (this.insertForm.result) data.result = this.insertForm.result
            if (this.isInsert) {
              furtherEducation_insert(data).then(res => {
                if (res.code === 200) {
                  this.dataList.unshift(res.data)
                  this.defaultDataList.push(res.data)
                  this.init_data(this.defaultDataList)
                  this.page.totalResult+=1
                  this.$refs.XTable.setCurrentRow(this.dataList[0])
                  this.$message.success('保存成功')
                  this.insertSuccess = true
                  this.insertModal = false
                } else {
                  this.$message.error(res.message)
                }
              })
            } else {
              data.flowId = this.flowId
              furtherEducation_update(data).then(res => {
                if (res.code === 200) {
                  Object.assign(this.dataList[this.currentIndex],res.data)
                  this.defaultDataList.forEach(item=>{
                  	if(res.data.flowId==item.flowId){
                  	  Object.assign(item,res.data)
                  	}
                  })
                  this.init_data(this.defaultDataList)
                  this.$message.success('修改成功')
                  this.insertModal = false
                } else {
                  this.$message.error(res.message)
                }
              })
            }
          } else {
            return false;
          }
        })
      },
      insertEvent() {
        this.insertForm = {
          empId: '',
          sportId: '',
          sportItemId: '',
          beginDate: '',
          endDate: '',
          contentTypeId: '',
          content: '',
          hostTypeId: '',
          orgName: '',
          trainingLevelId: '',
          perio: '',
          address: '',
          instructor: '',
          result: '',
        }
        this.sportChangesportItemData = {}
        this.isInsert = true
        this.insertModal = true
      },
      sportItemChange(e) {
        this.insertForm.empId = ''
        this.dict_emp = {}
        let data = {}
        if (this.insertForm.sportId || this.searchForm.sportId) data.sportId = this.insertForm.sportId || this
          .searchForm.sportId
        if (this.insertForm.sportItemId || this.searchForm.sportItemId) data.sportItemId = this.insertForm
          .sportItemId || this.searchForm.sportItemId || e
        currentRoleEmployee(data).then(res2 => {
          let dict2 = {}
          res2.data.forEach(item=>{
            dict2[item.empId] = item.name
          })
          this.empData = dict2
        })
      },
      sportChange(e) {
        this.insertForm.sportItemId = ''
        this.insertForm.empId = ''
        this.searchForm.sportItemId = ''
        this.searchForm.empId = ''
        sport_item_by_sportId({
          sportId: e || this.insertForm.sportId || this.searchForm.sportId
        }).then(res => {
          if (res.code === 200) {
            this.sportItemData = res.data
            let dict = {}
            if(this.sportItemData.length!=0){
              this.sportItemData.forEach(item=>{
                dict[item.sportItemId] = item.name
              })
            }
            this.dict_sportItem = dict
            let data = {}
            if (this.insertForm.sportId || this.searchForm.sportId) data.sportId = this.insertForm.sportId || this
              .searchForm.sportId || e
            if (this.insertForm.sportItemId || this.searchForm.sportItemId) data.sportItemId = this.insertForm
              .sportItemId || this.searchForm.sportItemId
              console.log(data)
            currentRoleEmployee(data).then(res2 => {
              let dict2 = {}
              res2.data.forEach(item=>{
                dict2[item.empId] = item.name
              })
              this.empData = dict2
            })
          }
        })
      },
      exportData() {
        this.$refs.XTable.exportData({
          filename: this.$store.state.user.org+'教职员'+this.$route.meta.title, type: 'csv',
          data: this.search?this.dataList:this.defaultDataList
        })
      },
      printEvent() {
        let topHtml = '<h2>进修培训</h2>'
        this.searchEvent()
        setTimeout(() => {
          this.$refs.XTable.print({
            sheetName: '进修培训',
            beforePrintMethod: ({
              content
            }) => {
              return topHtml + content
            }
          })
        }, 1000)
      },
      searchEvent() {
        const filterName = this.$XEUtils.toValueString(this.filterName).trim().toLowerCase()
        if (filterName) {
          const filterRE = filterName
          const searchProps = this.searchProps
          const rest = this.defaultDataList.filter(item => searchProps.some(key => this.$XEUtils.toValueString(item[
            key]).toLowerCase().indexOf(filterName) > -1))
          this.dataList = rest.map(row => {
            const item = Object.assign({}, row)
            searchProps.forEach(key => {
              item[key] = this.$XEUtils.toValueString(item[key]).replace(filterRE, match => match)
            })
            return item
          })
          this.page = {
            currentPage: 1,
            pageSize: 10,
            totalResult: 0
          }
          this.search = true
        } else {
          this.dataList = this.defaultDataList
     }
      },
      furtherEducation_selectByOrg() {
        furtherEducation_selectByOrg().then(res => {
          if (res.code === 200 && res.data.length != 0) {
            this.init_data(res.data)
          } else {
            this.defaultDataList = []
          }
        }).then(() => {
          this.findList()
        })
      },
      init_data(data) {
        if(data.length==0) return
        data.forEach(item => {
          item.empId2Type = this.dict_empId2TypeId[item.empId]
          item.jempId2Type = this.dict_jempId2TypeId[item.empId]
          item.emp = this.dict_emp[item.empId]
          item.beginDate = this.$moment(item.beginDate).format('YYYY-MM-DD') == 'Invalid date' ? '' : this.$moment(
            item.beginDate).format('YYYY-MM-DD')
          item.endDate = this.$moment(item.endDate).format('YYYY-MM-DD') == 'Invalid date' ? '' : this.$moment(item
            .endDate).format('YYYY-MM-DD')
          item.contentType = this.dict_contentType[item.contentTypeId]
          item.hostType = this.dict_hostType[item.hostTypeId]
          item.trainingLevel = this.dict_trainingLevel[item.trainingLevelId]
          item.createUser = this.dict_userId2empName[item.createUserId]
          if (item.checkUserId) {
            item.checkUser = this.dict_userId2empName[item.checkUserId]
          } else {
            item.checkUser = '未审核'
          }
        })
        this.searchProps = Object.keys(data[0])
        this.defaultDataList = data
      },
      init_dict() {
        return new Promise((resolve, reject) => {
          userId2EmpName().then(res => {
            this.dict_userId2empName = res
          })
          currentRoleEmployee().then(res => {
            let dict = {}
            res.data.forEach(item=>{
              dict[item.empId] = item.name
            })
            this.dict_emp = dict
            this.empData = dict
          })
          sport_by_org().then(res=>{
            this.dict_sport = res
          })
          sport_item_cache().then(res=>{
            this.dict_sportItem = res
          })
          genEmpType(true).then(res => {
            var dict_jempId2TypeId = {}
            var dict_empId2TypeId = {}
            var dict_pId2TypeId = {}
            var dict_jpId2TypeId = {}
            var dict_empType = {
              1: '教练员',
              2: '文化教师',
              3: '科医人员',
              4: '行政管理',
            }
            var employees = res.data;
            for (var i = 0; i < employees.length; i++) {
              var jempTypeName = '';
              if (employees[i].height.length > 0) {
                var ids = employees[i].height.split(',');
                for (var j = 0; j < ids.length; j++) {
                  jempTypeName += dict_empType[ids[j]] + ','
                }
                jempTypeName = jempTypeName.substring(0, jempTypeName.length - 1)
                dict_jempId2TypeId[employees[i].empId] = jempTypeName
                dict_jpId2TypeId[employees[i].pid] = jempTypeName
              } else {
                dict_jempId2TypeId[employees[i].empId] = ''
                dict_jpId2TypeId[employees[i].pid] = ''
              }
              if (employees[i].empTypeId) {
                dict_empId2TypeId[employees[i].empId] = dict_empType[employees[i].empTypeId]
                dict_pId2TypeId[employees[i].pid] = dict_empType[employees[i].empTypeId]
              } else {
                dict_empId2TypeId[employees[i].empId] = '';
                dict_pId2TypeId[employees[i].pid] = '';
              }
            }
            this.dict_empId2TypeId = dict_empId2TypeId
            this.dict_jempId2TypeId = dict_jempId2TypeId
            this.dict_pId2TypeId = dict_pId2TypeId
            this.dict_jpId2TypeId = dict_jpId2TypeId
            this.dict_empType = dict_empType
            resolve()
          })
        })
      },
      handlePageChange({
        currentPage,
        pageSize
      }) {
        this.page.currentPage = currentPage
        this.page.pageSize = pageSize
        this.findList()
      },
      sortChange() {
      	if(!this.search){
          this.page.currentPage = 1
      	  this.page.pageSize = this.defaultDataList.length
      	  this.findList()
      	}else{
      	  this.page.pageSize = this.dataList.length
      	}
      },
      findList() {
        this.loading = true
        setTimeout(() => {
          if(this.insertSuccess){
            this.page.totalResult = this.defaultDataList.length
            this.page.currentPage = Math.ceil(this.page.totalResult/this.page.pageSize)
            this.dataList = this.defaultDataList.slice((this.page.currentPage - 1) * this.page
              .pageSize, this.page.currentPage * this.page.pageSize)
            this.$refs.XTable.setCurrentRow(this.dataList[this.dataList.length-1])
            this.insertSuccess = false
          }else{
            this.page.totalResult = this.defaultDataList.length
            this.dataList = this.defaultDataList.slice((this.page.currentPage - 1) * this.page
              .pageSize, this.page.currentPage * this.page.pageSize)
          }
          this.loading = false
        }, 300)
      },
    }
  }
</script>

<style lang="scss" scoped>

</style>
